
using System.Linq;
using System.Web.Mvc;
using Ezio.Models;

namespace Ezio.Controllers
{
    public class TiposMenusController : Controller
    {
        DataProvider Provider = new DataProvider();
        
        
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Agregar(TiposMenus TiposMenu)
        {
            Provider.AddToTiposMenus(TiposMenu);
            return RedirectToAction("Index", new { Success = Provider.TrySaveChanges() });
        }
        public ActionResult Index(bool? Success)
        {
            string Message = Success.HasValue ? Success.Value ? "" : "Ha ocurrido un error al procesar su peticion" : "";
            
            ViewData["TiposMenus"] = Provider.TiposMenus.ToList();
            ViewData["Message"] = Message;
            return View("Index");
        }
        public ActionResult Editar(int Id)
        {
            ViewData["TiposMenu"] = Provider.TiposMenus.Single(t => t.IdTipoMenu == Id);
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public bool Update(TiposMenus TipoMenu)
        {
            TiposMenus myTiposMenu= Provider.TiposMenus.Single(t => t.IdTipoMenu == TipoMenu.IdTipoMenu);
            myTiposMenu.Copy(TipoMenu);
            return Provider.TrySaveChanges();
        }

        public ActionResult Eliminar(int Id)
        {
            Provider.TiposMenus.DeleteObject(Provider.TiposMenus.Single(t => t.IdTipoMenu == Id));
            return RedirectToAction("Index", new { Success = Provider.TrySaveChanges() }); ;
        }

    }
}
